package com.darsystems.foghourz.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class GoogleAuthorizer implements Authorizer {

	public void checkLoginStatus(final AuthorizeCallback callback) {
		GoogleLoginServiceAsync loginService = GWT.create(GoogleLoginService.class);
	    loginService.login(GWT.getHostPageBaseURL(), new AsyncCallback<GoogleLoginInfo>() {
	      public void onFailure(Throwable error) {
	    	  callback.onFailure(error);
	      }

	      public void onSuccess(GoogleLoginInfo result) {
	        
	        if(result.isLoggedIn()) {
	        	callback.onLoggedIn(result.getLogoutUrl());
	        } else {
	        	callback.onNotLoggedIn(result.getLoginUrl());
	        }
	      }
	    });
	}
	
	public String getName()
	{
		return "Google";
	}
	
	public boolean getAutoRedirect()
	{
		return false;
	}

}
